<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.9.1"/>
<title>opennars: nars.language.Variable.findSubstitute</title>
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<link href="../../navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../resize.js"></script>
<script type="text/javascript" src="../../navtreedata.js"></script>
<script type="text/javascript" src="../../navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { init_search(); });
</script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">opennars
   &#160;<span id="projectnumber">1.5.5</span>
   </div>
   <div id="projectbrief">1.5-ish</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.9.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "../../search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="../../index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="../../pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="../../namespaces.html"><span>Packages</span></a></li>
      <li><a href="../../annotated.html"><span>Classes</span></a></li>
      <li><a href="../../files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="../../search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="../../search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('de/da5/classnars_1_1language_1_1Variable_a997e50c6a8ea7057483f057bc703a4f0.html','../../');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="contents">
<a class="anchor" id="a997e50c6a8ea7057483f057bc703a4f0"></a>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">static boolean nars.language.Variable.findSubstitute </td>
          <td>(</td>
          <td class="paramtype">char&#160;</td>
          <td class="paramname"><em>type</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="../../d8/db8/classnars_1_1language_1_1Term.html">Term</a>&#160;</td>
          <td class="paramname"><em>term1</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="../../d8/db8/classnars_1_1language_1_1Term.html">Term</a>&#160;</td>
          <td class="paramname"><em>term2</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">HashMap&lt; <a class="el" href="../../d8/db8/classnars_1_1language_1_1Term.html">Term</a>, <a class="el" href="../../d8/db8/classnars_1_1language_1_1Term.html">Term</a> &gt;&#160;</td>
          <td class="paramname"><em>map1</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">HashMap&lt; <a class="el" href="../../d8/db8/classnars_1_1language_1_1Term.html">Term</a>, <a class="el" href="../../d8/db8/classnars_1_1language_1_1Term.html">Term</a> &gt;&#160;</td>
          <td class="paramname"><em>map2</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">static</span><span class="mlabel">private</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>To recursively find a substitution that can unify two Terms without changing them. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">type</td><td>The type of <a class="el" href="../../de/da5/classnars_1_1language_1_1Variable.html" title="A variable term, which does not correspond to a concept. ">Variable</a> to be substituted </td></tr>
    <tr><td class="paramname">term1</td><td>The first <a class="el" href="../../d8/db8/classnars_1_1language_1_1Term.html" title="Term is the basic component of Narsese, and the object of processing in NARS. ">Term</a> to be unified </td></tr>
    <tr><td class="paramname">term2</td><td>The second <a class="el" href="../../d8/db8/classnars_1_1language_1_1Term.html" title="Term is the basic component of Narsese, and the object of processing in NARS. ">Term</a> to be unified </td></tr>
    <tr><td class="paramname">subs</td><td>The substitution formed so far </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>The substitution that unifies the two Terms </dd></dl>

<p>Definition at line <a class="el" href="../../d2/de0/Variable_8java_source.html#l00145">145</a> of file <a class="el" href="../../d2/de0/Variable_8java_source.html">Variable.java</a>.</p>

<p>References <a class="el" href="../../d5/d0e/CompoundTerm_8java_source.html#l00356">nars.language.CompoundTerm.componentAt()</a>, <a class="el" href="../../d8/df2/Term_8java_source.html#l00094">nars.language.Term.equals()</a>, <a class="el" href="../../d2/de0/Variable_8java_source.html#l00053">nars.language.Variable.getType()</a>, and <a class="el" href="../../d5/d0e/CompoundTerm_8java_source.html#l00347">nars.language.CompoundTerm.size()</a>.</p>

<p>Referenced by <a class="el" href="../../d2/de0/Variable_8java_source.html#l00195">nars.language.Variable.hasSubstitute()</a>, and <a class="el" href="../../d2/de0/Variable_8java_source.html#l00122">nars.language.Variable.unify()</a>.</p>
<div class="fragment"><div class="line"><a name="l00146"></a><span class="lineno">  146</span>&#160;                                                                {</div>
<div class="line"><a name="l00147"></a><span class="lineno">  147</span>&#160;        <a class="code" href="../../d8/db8/classnars_1_1language_1_1Term_a2d9973aada6190dd60b48a34448094c9.html#a2d9973aada6190dd60b48a34448094c9">Term</a> t;</div>
<div class="line"><a name="l00148"></a><span class="lineno">  148</span>&#160;        <span class="keywordflow">if</span> ((term1 instanceof <a class="code" href="../../de/da5/classnars_1_1language_1_1Variable_a084a030f6fdad3d1274ee3ede04b9087.html#a084a030f6fdad3d1274ee3ede04b9087">Variable</a>) &amp;&amp; ((Variable) term1).<a class="code" href="../../de/da5/classnars_1_1language_1_1Variable_a453637a49d162fd4bb44725ff7b5965b.html#a453637a49d162fd4bb44725ff7b5965b">getType</a>() == type) {</div>
<div class="line"><a name="l00149"></a><span class="lineno">  149</span>&#160;            t = map1.get((Variable) term1);</div>
<div class="line"><a name="l00150"></a><span class="lineno">  150</span>&#160;            <span class="keywordflow">if</span> (t != null) {</div>
<div class="line"><a name="l00151"></a><span class="lineno">  151</span>&#160;                <span class="keywordflow">return</span> t.equals(term2);</div>
<div class="line"><a name="l00152"></a><span class="lineno">  152</span>&#160;            } <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00153"></a><span class="lineno">  153</span>&#160;                map1.put((Variable) term1, term2);</div>
<div class="line"><a name="l00154"></a><span class="lineno">  154</span>&#160;                <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
<div class="line"><a name="l00155"></a><span class="lineno">  155</span>&#160;            }</div>
<div class="line"><a name="l00156"></a><span class="lineno">  156</span>&#160;        }</div>
<div class="line"><a name="l00157"></a><span class="lineno">  157</span>&#160;        <span class="keywordflow">if</span> ((term2 instanceof Variable) &amp;&amp; ((Variable) term2).<a class="code" href="../../de/da5/classnars_1_1language_1_1Variable_a453637a49d162fd4bb44725ff7b5965b.html#a453637a49d162fd4bb44725ff7b5965b">getType</a>() == type) {</div>
<div class="line"><a name="l00158"></a><span class="lineno">  158</span>&#160;            t = map2.get((Variable) term2);</div>
<div class="line"><a name="l00159"></a><span class="lineno">  159</span>&#160;            <span class="keywordflow">if</span> (t != null) {</div>
<div class="line"><a name="l00160"></a><span class="lineno">  160</span>&#160;                <span class="keywordflow">return</span> t.equals(term1);</div>
<div class="line"><a name="l00161"></a><span class="lineno">  161</span>&#160;            } <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00162"></a><span class="lineno">  162</span>&#160;                map2.put((Variable) term2, term1);</div>
<div class="line"><a name="l00163"></a><span class="lineno">  163</span>&#160;                <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
<div class="line"><a name="l00164"></a><span class="lineno">  164</span>&#160;            }</div>
<div class="line"><a name="l00165"></a><span class="lineno">  165</span>&#160;        }</div>
<div class="line"><a name="l00166"></a><span class="lineno">  166</span>&#160;        <span class="keywordflow">if</span> ((term1 instanceof CompoundTerm) &amp;&amp; term1.getClass().equals(term2.getClass())) {</div>
<div class="line"><a name="l00167"></a><span class="lineno">  167</span>&#160;            CompoundTerm cTerm1 = (CompoundTerm) term1;</div>
<div class="line"><a name="l00168"></a><span class="lineno">  168</span>&#160;            CompoundTerm cTerm2 = (CompoundTerm) term2;</div>
<div class="line"><a name="l00169"></a><span class="lineno">  169</span>&#160;            <span class="keywordflow">if</span> (cTerm1.size() != (cTerm2).size()) {</div>
<div class="line"><a name="l00170"></a><span class="lineno">  170</span>&#160;                <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
<div class="line"><a name="l00171"></a><span class="lineno">  171</span>&#160;            }</div>
<div class="line"><a name="l00172"></a><span class="lineno">  172</span>&#160;            <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; cTerm1.size(); i++) {</div>
<div class="line"><a name="l00173"></a><span class="lineno">  173</span>&#160;                <a class="code" href="../../d8/db8/classnars_1_1language_1_1Term_a2d9973aada6190dd60b48a34448094c9.html#a2d9973aada6190dd60b48a34448094c9">Term</a> t1 = cTerm1.componentAt(i);</div>
<div class="line"><a name="l00174"></a><span class="lineno">  174</span>&#160;                <a class="code" href="../../d8/db8/classnars_1_1language_1_1Term_a2d9973aada6190dd60b48a34448094c9.html#a2d9973aada6190dd60b48a34448094c9">Term</a> t2 = cTerm2.componentAt(i);</div>
<div class="line"><a name="l00175"></a><span class="lineno">  175</span>&#160;                <span class="keywordtype">boolean</span> haveSub = <a class="code" href="../../de/da5/classnars_1_1language_1_1Variable_a997e50c6a8ea7057483f057bc703a4f0.html#a997e50c6a8ea7057483f057bc703a4f0">findSubstitute</a>(type, t1, t2, map1, map2);</div>
<div class="line"><a name="l00176"></a><span class="lineno">  176</span>&#160;                <span class="keywordflow">if</span> (!haveSub) {</div>
<div class="line"><a name="l00177"></a><span class="lineno">  177</span>&#160;                    <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
<div class="line"><a name="l00178"></a><span class="lineno">  178</span>&#160;                }</div>
<div class="line"><a name="l00179"></a><span class="lineno">  179</span>&#160;            }</div>
<div class="line"><a name="l00180"></a><span class="lineno">  180</span>&#160;            <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
<div class="line"><a name="l00181"></a><span class="lineno">  181</span>&#160;        }</div>
<div class="line"><a name="l00182"></a><span class="lineno">  182</span>&#160;        <span class="keywordflow">if</span> (!(term1 instanceof Variable) &amp;&amp; !(term2 instanceof Variable) &amp;&amp; term1.equals(term2)) {<span class="comment">// for constant, also shortcut for variable and compound</span></div>
<div class="line"><a name="l00183"></a><span class="lineno">  183</span>&#160;            <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
<div class="line"><a name="l00184"></a><span class="lineno">  184</span>&#160;        }</div>
<div class="line"><a name="l00185"></a><span class="lineno">  185</span>&#160;        <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
<div class="line"><a name="l00186"></a><span class="lineno">  186</span>&#160;    }</div>
<div class="ttc" id="classnars_1_1language_1_1Variable_a453637a49d162fd4bb44725ff7b5965b_html_a453637a49d162fd4bb44725ff7b5965b"><div class="ttname"><a href="../../de/da5/classnars_1_1language_1_1Variable_a453637a49d162fd4bb44725ff7b5965b.html#a453637a49d162fd4bb44725ff7b5965b">nars.language.Variable.getType</a></div><div class="ttdeci">char getType()</div><div class="ttdoc">Get the type of the variable. </div><div class="ttdef"><b>Definition:</b> <a href="../../d2/de0/Variable_8java_source.html#l00053">Variable.java:53</a></div></div>
<div class="ttc" id="classnars_1_1language_1_1Term_a2d9973aada6190dd60b48a34448094c9_html_a2d9973aada6190dd60b48a34448094c9"><div class="ttname"><a href="../../d8/db8/classnars_1_1language_1_1Term_a2d9973aada6190dd60b48a34448094c9.html#a2d9973aada6190dd60b48a34448094c9">nars.language.Term.Term</a></div><div class="ttdeci">Term()</div><div class="ttdoc">Default constructor that build an internal Term. </div><div class="ttdef"><b>Definition:</b> <a href="../../d8/df2/Term_8java_source.html#l00051">Term.java:51</a></div></div>
<div class="ttc" id="classnars_1_1language_1_1Variable_a997e50c6a8ea7057483f057bc703a4f0_html_a997e50c6a8ea7057483f057bc703a4f0"><div class="ttname"><a href="../../de/da5/classnars_1_1language_1_1Variable_a997e50c6a8ea7057483f057bc703a4f0.html#a997e50c6a8ea7057483f057bc703a4f0">nars.language.Variable.findSubstitute</a></div><div class="ttdeci">static boolean findSubstitute(char type, Term term1, Term term2, HashMap&lt; Term, Term &gt; map1, HashMap&lt; Term, Term &gt; map2)</div><div class="ttdoc">To recursively find a substitution that can unify two Terms without changing them. </div><div class="ttdef"><b>Definition:</b> <a href="../../d2/de0/Variable_8java_source.html#l00145">Variable.java:145</a></div></div>
<div class="ttc" id="classnars_1_1language_1_1Variable_a084a030f6fdad3d1274ee3ede04b9087_html_a084a030f6fdad3d1274ee3ede04b9087"><div class="ttname"><a href="../../de/da5/classnars_1_1language_1_1Variable_a084a030f6fdad3d1274ee3ede04b9087.html#a084a030f6fdad3d1274ee3ede04b9087">nars.language.Variable.Variable</a></div><div class="ttdeci">Variable(String s)</div><div class="ttdoc">Constructor, from a given variable name. </div><div class="ttdef"><b>Definition:</b> <a href="../../d2/de0/Variable_8java_source.html#l00036">Variable.java:36</a></div></div>
</div><!-- fragment -->
<p><div id="dynsection-0" onclick="return toggleVisibility(this)" class="dynheader closed" style="cursor:pointer;">
  <img id="dynsection-0-trigger" src="../../closed.png" alt="+"/> Here is the call graph for this function:</div>
<div id="dynsection-0-summary" class="dynsummary" style="display:block;">
</div>
<div id="dynsection-0-content" class="dyncontent" style="display:none;">
<div class="center"><div class="zoom"><iframe scrolling="no" frameborder="0" src="../../de/da5/classnars_1_1language_1_1Variable_a997e50c6a8ea7057483f057bc703a4f0_a997e50c6a8ea7057483f057bc703a4f0_cgraph.svg" width="100%" height="442"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
</div>
</div>
</p>

<p><div id="dynsection-1" onclick="return toggleVisibility(this)" class="dynheader closed" style="cursor:pointer;">
  <img id="dynsection-1-trigger" src="../../closed.png" alt="+"/> Here is the caller graph for this function:</div>
<div id="dynsection-1-summary" class="dynsummary" style="display:block;">
</div>
<div id="dynsection-1-content" class="dyncontent" style="display:none;">
<div class="center"><div class="zoom"><iframe scrolling="no" frameborder="0" src="../../de/da5/classnars_1_1language_1_1Variable_a997e50c6a8ea7057483f057bc703a4f0_a997e50c6a8ea7057483f057bc703a4f0_icgraph.svg" width="100%" height="427"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
</div>
</div>
</p>

</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="../../d7/d81/namespacenars.html">nars</a></li><li class="navelem"><a class="el" href="../../d0/d72/namespacenars_1_1language.html">language</a></li><li class="navelem"><a class="el" href="../../de/da5/classnars_1_1language_1_1Variable.html">Variable</a></li>
    <li class="footer">Generated on Sun Jan 10 2016 18:03:59 for opennars by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="../../doxygen.png" alt="doxygen"/></a> 1.8.9.1 </li>
  </ul>
</div>
</body>
</html>
